package com.lzq.mq.client.consumer;

import com.alibaba.fastjson2.JSON;
import com.lzq.mq.common.coder.TcpMsg;
import com.lzq.mq.common.dto.CreateTopicReqDTO;
import com.lzq.mq.common.dto.CreateTopicRespDTO;
import com.lzq.mq.common.enums.BrokerEventCode;
import com.lzq.mq.common.remote.BrokerNettyRemoteClient;

import java.util.UUID;

public class CreateTopicCommand {

    public static void main(String[] args) {
        BrokerNettyRemoteClient brokerNettyRemoteClient = new BrokerNettyRemoteClient("127.0.0.1", 9093);
        brokerNettyRemoteClient.buildConnection();
        String msgId = UUID.randomUUID().toString();
        CreateTopicReqDTO createTopicReqDTO = new CreateTopicReqDTO();
        createTopicReqDTO.setTopic("pay_success");
        createTopicReqDTO.setMsgId(msgId);
        createTopicReqDTO.setQueueSize(3);
        TcpMsg respMsg = brokerNettyRemoteClient.sendSyncMsg(
                new TcpMsg(BrokerEventCode.CREATE_TOPIC.getCode(), JSON.toJSONBytes(createTopicReqDTO)),
                msgId
        );
        CreateTopicRespDTO createTopicRespDTO = JSON.parseObject(respMsg.getBody(), CreateTopicRespDTO.class);
        System.out.println("resp:" + createTopicRespDTO);
    }
}
